using System;
using UnityEngine;

namespace DanielSig.UnityExtensions
{
	public static class XBounds
	{
		public static void Draw(this Bounds b, Color color, Transform localSpace)
		{
			b.From(localSpace).Draw(color, localSpace.rotation);
		}
		public static void Draw(this Bounds b, Color color)
		{
			b.Draw(color, Quaternion.identity);
		}
		public static void Draw(this Bounds b, Color color, Quaternion rotation)
		{
			Vector3 s = b.center - (rotation * b.extents);
			Vector3 forward = rotation * Vector3.forward;
			Vector3 back = rotation * Vector3.back;
			Vector3 up = rotation * Vector3.up;
			//Vector3 down = rotation * Vector3.down;
			Vector3 left = rotation * Vector3.left;
			Vector3 right = rotation * Vector3.right;
			
			s.RayTo(color,
			right * b.size.x,
			forward * b.size.z,
			left * b.size.x,
			back * b.size.z,
			up * b.size.y,
			right * b.size.x,
			forward * b.size.z,
			left * b.size.x,
			back * b.size.z);
			(s + right * b.size.x).RayTo(color, up * b.size.y);
			(s + forward * b.size.z).RayTo(color, up * b.size.y);
			(s + right * b.size.x + forward * b.size.z).RayTo(color, up * b.size.y);
		}
		public static Bounds ToLossy(this Bounds b, Transform localSpace)
		{
			return new Bounds(b.center.To(localSpace), b.size.Divide(localSpace.lossyScale));
		}
		public static Bounds FromLossy(this Bounds b, Transform localSpace)
		{
			return new Bounds(b.center.From(localSpace), b.size.GetScaled(localSpace.lossyScale));
		}
		public static Bounds To(this Bounds b, Transform localSpace)
		{
			return new Bounds(b.center.To(localSpace), b.size.Divide(localSpace.localScale));
		}
		public static Bounds From(this Bounds b, Transform localSpace)
		{
			return new Bounds(b.center.From(localSpace), b.size.GetScaled(localSpace.localScale));
		}
	}
}

